#include<cstring>
char a[10001][80];
int r,c;
int gcd(int a,int b)
{
	if(b%a==0)return a;
	else return gcd(b%a,a);
}
int lcm(int a,int b)
{
	return a*b/gcd(a,b);
}
int max(int x,int y)
{
	return x>y?x:y;
}
int work(char p[])
{
	int next[80];
	memset(next,0,sizeof(next));
	next[1]=0;
	for(int i=2;i<=c;i++)
	{
		int j=next[i-1];
		while(p[i]!=p[j+1]&&j>0)
			j=next[j];
		if(p[i]==p[j+1])next[i]=j+1;
		else next[i]=0;
	}
	return c-next[c];
}
int work2(int p)
{
	int next[10080];
	memset(next,0,sizeof(next));
	next[1]=0;
	for(int i=2;i<=r;i++)
	{
		int j=next[i-1];
		while(a[i][p]!=a[j+1][p]&&j>0)
			j=next[j];
		if(a[i][p]==a[j+1][p])next[i]=j+1;
		else next[i]=0;
	}
	return r-next[r];
}


int main()
{
	freopen("test.in","r",stdin);
	scanf("%d%d",&r,&c);
	int alcm=1;
	scanf("%c",&a[0][0]);
	for(int i=1;i<=r;i++)
		for(int j=1;j<=c+1;j++)
			scanf("%c",&a[i][j]);
	for(int i=1;i<=r;i++)
	{
		int tem=work(a[i]);
		//printf("%d\n",tem);
		alcm=lcm(alcm,tem);
		if(alcm>=c)
		{
			alcm=c;
			break;
		}
	}
	int amax=-1;
	for(int i=1;i<=alcm;i++)
	{
		int tem=work2(i);
		amax=max(tem,amax);
		if(amax==r)break;
	}
	printf("%d\n",amax*alcm);
	return 0;
}






